package com.redteam.xomtro.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.redteam.xomtro.MainActivity;
import com.redteam.xomtro.R;
import com.redteam.xomtro.RoomDetailActivity;
import com.redteam.xomtro.adapters.RoomListAdapter;
import com.redteam.xomtro.entities.Room;
import com.redteam.xomtro.views.EDGirdView;

import java.util.ArrayList;

/**
 * Created by AnhThuanIT on 5/23/2014.
 */
public class HomeFragment extends MainFragment implements AdapterView.OnItemClickListener {
    private EDGirdView listViewRoom;
    RoomListAdapter roomListAdapter;
    private ArrayList<Room> roomList;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
        View r = inflater.inflate(R.layout.fragment_home, container, false);
        assert r != null;
        roomList = Room.getListRoomExample();
        listViewRoom = (EDGirdView) r.findViewById(android.R.id.list);
        for (int i = 0; i < getResources().getInteger(R.integer.num_cols); i++) {
            roomList.add(0, new Room("null"));
        }
        listViewRoom.setEmptyView(emptyView);
        listViewRoom.setOnItemClickListener(this);
        listViewRoom.setOnDetectScrollListener(this);

        if (roomList != null) {
            roomListAdapter = new RoomListAdapter(roomList, activity, options, optionsAvatar, fontLight, fontBold, imageLoader);
        }
        listViewRoom.setAdapter(roomListAdapter);
        return r;
    }

    @Override
    public void onDestroyView() {
        // Sets variables to null, to avoid memory leaks
        listViewRoom.invalidate();
        // Always call the super method last
        super.onDestroyView();
    }


    public HomeFragment(MainActivity mainActivity) {
        super(mainActivity);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent it = new Intent(activity, RoomDetailActivity.class);
        startActivity(it);
    }
}

